package com.rh.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 当项目一启动时 读取配置文件的配置类
 */
@Component
public class ConstantPropertiesUtils implements InitializingBean {
    //1.实现InitializingBean，当项目启动的时候会采用@Value注解的方式读配置文件中的值
    @Value("${aliyun.oss.file.endpoint}")
   private String endPoint;
    @Value("${aliyun.oss.file.accessKeyId}")
   private String accessKeyId;
    @Value("${aliyun.oss.file.accessKeySecret}")
   private String accessKeySecret;
    @Value("${aliyun.oss.file.bucketname}")
   private String bucketName;

    //3.定义公开静态常量
    public static String END_POINT;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;
    //2.当@Value初始化完成之后，这个方法执行
    @Override
    public void afterPropertiesSet() throws Exception {
    //4.给静态常量赋值
        END_POINT=endPoint;
        ACCESS_KEY_ID=accessKeyId;
        ACCESS_KEY_SECRET=accessKeySecret;
        BUCKET_NAME=bucketName;
    }
}
